package com.inspector.app.util;

import android.text.TextUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

public class CollectionUtils {
    private static final String DELIMITER = ",";

    public CollectionUtils() {
    }

    public static <V> boolean isEmpty(Collection<V> c) {
        return c == null || c.size() == 0;
    }

    public static String join(Iterable tokens) {
        return tokens == null ? "" : TextUtils.join(",", tokens);
    }

    public static <T> List<T> arrayToList(T... array) {
        return Arrays.asList(array);
    }

    public static <T> Set<T> arrayToSet(T... array) {
        return new HashSet(arrayToList(array));
    }

    public static Object[] listToArray(Collection<?> c) {
        return !isEmpty(c) ? c.toArray() : null;
    }

    public static <T> Set<T> listToSet(List<T> list) {
        return new HashSet(list);
    }

    public static <T> List<T> setToList(Set<T> set) {
        return new ArrayList(set);
    }

    public static <T> String traverseCollection(Collection<T> c) {
        if (!isEmpty(c)) {
            int len = c.size();
            StringBuilder builder = new StringBuilder(len);
            int i = 0;
            Iterator i$ = c.iterator();

            while(i$.hasNext()) {
                T t = (T) i$.next();
                if (t != null) {
                    builder.append(t.toString());
                    ++i;
                    if (i < len) {
                        builder.append(",");
                    }
                }
            }

            return builder.toString();
        } else {
            return null;
        }
    }
}
